package tge

import (
	"log"
	"os"
	"io"
	"os/signal"
)

var logger = log.New(os.Stdout, "[TGE] ", log.LstdFlags | log.Lshortfile)
var Logger = logger

var CloseSig = make(chan bool)

// 启动服务器，按顺序执行逻辑模块
func Run(mods... Module) {
	logger.Println("tge Run")
	for _, m := range mods {
		RegisterModule(m)
	}
	InitModule()
	ch := make(chan os.Signal)
	signal.Notify(ch, os.Interrupt, os.Kill)
	select {
	case <-CloseSig:
		logger.Println("close by CloseSig")
	case e := <-ch:
		logger.Println(e)
	}
	DestroyModule()
}

func SetOutput(w io.Writer) {
	logger.SetOutput(w)
}
